package com.fowo.api.flow.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fowo.api.common.model.R;
import com.fowo.api.flow.entity.ProcessTemplates;
import com.fowo.api.flow.model.dto.*;
import com.fowo.api.flow.model.vo.*;
import com.fowo.api.flow.service.FlowService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @fileName: DemoFlowController
 * @Description: 代码目的，作用，如何工作
 * @Author: pzh
 * @Date: 2023/3/29 0029 15:23
 */
@Tag(name = "工作流")
@RequestMapping("/api/flow")
@RestController
public class FlowController {

    @Resource
    private FlowService flowService;

    @Operation(summary="通过模板id查看流程信息 会附带流程定义id")
    @GetMapping("process/detail")
    public R<ProcessTemplates> detail(@RequestParam("templateId") String templateId){
        return R.data(() -> flowService.detail(templateId));
    }

    @Operation(summary="通过流程定义id启动流程")
    @PostMapping("process/start")
    public  R<Object>  start(@RequestBody List<StartProcessInstanceDTO> startList){
        R<Object> start = flowService.start(startList);
        return start;
    }
    @Operation(summary="查看我发起的流程")
    @PostMapping("process/applyList")
    public R< Page<HistoryProcessInstanceVO>> applyList(@RequestBody ApplyDTO applyDTO){
        return R.data(() -> flowService.applyList(applyDTO));
    }

    @Operation(summary="查看我的待办")
    @PostMapping("process/toDoList")
    public R<Page<TaskVO>> toDoList(@RequestBody ApplyDTO taskDTO){
        return R.data(() -> flowService.toDoList(taskDTO));

    }

    @Operation(summary="查看我的已办")
    @PostMapping("process/doneList")
    public R<Page<TaskVO>> doneList(@RequestBody ApplyDTO taskDTO){
        return R.data(() -> flowService.doneList(taskDTO));
    }

    @Operation(summary="通过流程实例id查看详情")
    @PostMapping("process/instanceInfo")
    public R<HandleDataVO>instanceInfo(@RequestBody HandleDataDTO HandleDataDTO){
        return R.data(() -> flowService.instanceInfo(HandleDataDTO));
    }

    @Operation(summary="通过业务id查看详情")
    @PostMapping("process/recordFlow")
    public R<HandleDataVO>recordFlow(@RequestBody RecordFlowDTO recordFlowDTO){
        return R.data(() -> flowService.recordFlow(recordFlowDTO));
    }

    @Operation(summary="流程处理")
    @PostMapping("process/handle")
    public R handle(@RequestBody HandleDataDTO HandleDataDTO){
        R handle = flowService.handle(HandleDataDTO);
        return handle;
    }

    @Operation(summary="减签")
    @PostMapping("process/deleteMulti")
    public R deleteMulti(@RequestBody  List<String> executionIds){
        return R.run(() -> flowService.deleteMulti(executionIds));
    }
    @Operation(summary="查到签上的人")
    @PostMapping("process/queryMultiUsersInfo")
    public R<List<MultiVO>>  queryMultiUsersInfo( @RequestBody Map<String, Object> map){
        return R.data(() -> flowService.queryMultiUsersInfo(map));
    }

    @Operation(summary="查看退回节点")
    @GetMapping("process/queryNode")
    public R<List<NodeVo>>  queryNode(@RequestParam(value = "processInstanceId", required = false) String processInstanceId){
        return R.data(() -> flowService.queryNode(processInstanceId));
    }

    @Operation(summary="执行js脚本")
    @PostMapping("process/js")
    public R<Object>  callJsData(@RequestBody CallJsDataDTO callJsDataDTO){
        return R.data(() -> flowService.callJsData(callJsDataDTO));
    }

    @Operation(summary="流程处理")
    @PostMapping("process/batchApproval")
    public R batchApproval(@RequestBody List<HandleDataListDTO> handleDataListDTOList){
        R handle = flowService.batchApproval(handleDataListDTOList);
        return handle;
    }
}
